<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>自定义对象 | siphan</title>
    <meta name="description" content="一个简单易用的 JavaScript 前端加密库">
    <meta name="generator" content="VuePress 1.3.0">
    
    
    <link rel="preload" href="/siphan/assets/css/0.styles.bab5f12a.css" as="style"><link rel="preload" href="/siphan/assets/js/app.a096c374.js" as="script"><link rel="preload" href="/siphan/assets/js/2.b96ecc85.js" as="script"><link rel="preload" href="/siphan/assets/js/6.c506cd42.js" as="script"><link rel="prefetch" href="/siphan/assets/js/10.e5803348.js"><link rel="prefetch" href="/siphan/assets/js/11.1506d706.js"><link rel="prefetch" href="/siphan/assets/js/12.9fea4da3.js"><link rel="prefetch" href="/siphan/assets/js/3.c42c2ebd.js"><link rel="prefetch" href="/siphan/assets/js/4.5f9aa696.js"><link rel="prefetch" href="/siphan/assets/js/5.537dfae2.js"><link rel="prefetch" href="/siphan/assets/js/7.0de11c07.js"><link rel="prefetch" href="/siphan/assets/js/8.83590e60.js"><link rel="prefetch" href="/siphan/assets/js/9.b0b386d5.js">
    <link rel="stylesheet" href="/siphan/assets/css/0.styles.bab5f12a.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/siphan/" class="home-link router-link-active"><img src="https://s2.ax1x.com/2020/02/26/3aERFe.png" alt="siphan" class="logo"> <span class="site-name can-hide">siphan</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/siphan/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/siphan/guide/" class="nav-link">
  入门
</a></div><div class="nav-item"><a href="/siphan/API/" class="nav-link router-link-active">
  API
</a></div><div class="nav-item"><a href="http://service.shawroger.com/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  示例
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><a href="https://gitee.com/shawroger/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  仓库
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/siphan/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/siphan/guide/" class="nav-link">
  入门
</a></div><div class="nav-item"><a href="/siphan/API/" class="nav-link router-link-active">
  API
</a></div><div class="nav-item"><a href="http://service.shawroger.com/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  示例
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="nav-item"><a href="https://gitee.com/shawroger/siphan" target="_blank" rel="noopener noreferrer" class="nav-link external">
  仓库
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>API</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/siphan/API/" class="sidebar-link">加密函数</a></li><li><a href="/siphan/API/decrypt.html" class="sidebar-link">解密函数</a></li><li><a href="/siphan/API/config.html" class="active sidebar-link">自定义对象</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/siphan/API/config.html#usedkey" class="sidebar-link">usedKey</a></li><li class="sidebar-sub-header"><a href="/siphan/API/config.html#getkey" class="sidebar-link">getKey</a></li><li class="sidebar-sub-header"><a href="/siphan/API/config.html#setkey" class="sidebar-link">setKey</a></li><li class="sidebar-sub-header"><a href="/siphan/API/config.html#checkcustomkey" class="sidebar-link">checkCustomKey</a></li><li class="sidebar-sub-header"><a href="/siphan/API/config.html#getoriginkey" class="sidebar-link">getOriginKey</a></li><li class="sidebar-sub-header"><a href="/siphan/API/config.html#resetkey" class="sidebar-link">resetKey</a></li></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="自定义对象"><a href="#自定义对象" class="header-anchor">#</a> 自定义对象</h1> <p><strong>Siphan</strong> 提供了一个自定义对象 <strong>configKey</strong>，允许用来自定义字典。</p> <p>在 <strong>configKey</strong> 中提供了以下方法。</p> <h2 id="usedkey"><a href="#usedkey" class="header-anchor">#</a> usedKey</h2> <p><strong>usedKey</strong> 是一个数组，储存了 <strong>Siphan</strong> 当前使用的字典。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code>usedKey<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> configKey <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token comment">// 获取字典长度，不建议直接使用，请改用 getKey()</span>
<span class="token keyword">const</span> dictionaryLength <span class="token operator">=</span> configKey<span class="token punctuation">.</span>useKey<span class="token punctuation">.</span>length<span class="token punctuation">;</span>
</code></pre></div><ul><li>说明</li></ul> <ol><li><p><strong>usedKey</strong> 参数非常重要，<a href="/siphan/API/#checkkey">checkKey</a> 和 <a href="/siphan/API/#createkey">createKey</a> 函数都使用了该参数。</p></li> <li><p>只因为 <strong>usedKey</strong> 参数非常重要，请不要直接修改该参数，您可以使用 <strong>configKey</strong> 提供的方法来自定义字典。</p></li> <li><p>一般情况下，<strong>usedKey</strong> 参数永远不会被直接调用。</p></li></ol> <h2 id="getkey"><a href="#getkey" class="header-anchor">#</a> getKey</h2> <p><strong>getKey</strong> 是一个函数，返回 <strong>Siphan</strong> 当前使用的字典，即 <strong>usedKey</strong>。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token function">getKey</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> configKey <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token comment">// 获取字典长度</span>
<span class="token keyword">const</span> dictionaryLength <span class="token operator">=</span> configKey<span class="token punctuation">.</span><span class="token function">getKey</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span>length<span class="token punctuation">;</span>
</code></pre></div><ul><li>说明</li></ul> <ol><li><p><strong>getKey</strong> 是 <strong>usedKey</strong> 的只读函数。</p></li> <li><p>永远使用 <strong>getKey</strong> 来获取 <strong>usedKey</strong>，以保证安全性。</p></li></ol> <h2 id="setkey"><a href="#setkey" class="header-anchor">#</a> setKey</h2> <p><strong>setKey</strong> 是一个函数，用来修改 <strong>Siphan</strong> 当前使用的字典。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token function">setKey</span><span class="token punctuation">(</span>customKey<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span><span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> configKey <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;siphan&quot;</span><span class="token punctuation">;</span>

<span class="token comment">// 自定义字典</span>
configKey<span class="token punctuation">.</span><span class="token function">setKey</span><span class="token punctuation">(</span><span class="token punctuation">[</span>
    <span class="token string">&quot;a&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;b&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;c&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;d&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;e&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;f&quot;</span><span class="token punctuation">,</span> 
    <span class="token string">&quot;g&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;h&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;i&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;j&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;k&quot;</span><span class="token punctuation">,</span> <span class="token string">&quot;l&quot;</span>
<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><ul><li>说明</li></ul> <ol><li><p><strong>setKey</strong> 是 <strong>usedKey</strong> 的设置函数。</p></li> <li><p>永远使用 <strong>setKey</strong> 来自定义 <strong>usedKey</strong>，<strong>configKey</strong> 提供了 <strong>checkCustomKey</strong> 函数来进行控制（见下条）</p></li></ol> <h2 id="checkcustomkey"><a href="#checkcustomkey" class="header-anchor">#</a> checkCustomKey</h2> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token function">checkCustomKey</span><span class="token punctuation">(</span>customKey<span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">boolean</span>
</code></pre></div><p>这个函数在调用 <strong>setKey</strong> 函数时候对传入字典进行检查，只有满足以下要求的字符数组才能替换 <strong>usedKey</strong>：</p> <ol><li><p>已定义</p></li> <li><p>类型为数组</p></li> <li><p>长度大于 10</p></li> <li><p>数组元素类型都为字符串</p></li></ol> <blockquote><p>一般这个函数不需要调用，仅作为 <strong>configKey</strong> 内部方法在 <strong>setKey</strong> 中调用。</p></blockquote> <h2 id="getoriginkey"><a href="#getoriginkey" class="header-anchor">#</a> getOriginKey</h2> <p><strong>getOriginKey</strong> 用来获取 <strong>Siphan</strong> 的原生字典。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token function">getOriginKey</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">string</span><span class="token punctuation">[</span><span class="token punctuation">]</span>
</code></pre></div><blockquote><p><strong>getOriginKey</strong> 永远返回 <strong>Siphan</strong> 的原生字典，以保证原生字典不会被永久覆盖。</p></blockquote> <h2 id="resetkey"><a href="#resetkey" class="header-anchor">#</a> resetKey</h2> <p><strong>resetKey</strong> 函数将 <strong>Siphan</strong> 的字典复原成原生字典。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token function">resetKey</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token keyword">void</span>
</code></pre></div><blockquote><p><strong>resetKey</strong> 保证 <strong>Siphan</strong> 的字典在任何时机被还原成原生字典。</p></blockquote> <blockquote><p><strong>resetKey</strong> 一般用在 <strong>setKey</strong> 函数之后。</p></blockquote></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/siphan/API/decrypt.html" class="prev">
        解密函数
      </a></span> <!----></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/siphan/assets/js/app.a096c374.js" defer></script><script src="/siphan/assets/js/2.b96ecc85.js" defer></script><script src="/siphan/assets/js/6.c506cd42.js" defer></script>
  </body>
</html>
